package com.haha.helloworld.gridview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.haha.helloworld.R;

public class MyGridViewAdapter extends BaseAdapter {
    private Context myContext;
    private LayoutInflater myLayoutInflater;

    public MyGridViewAdapter(Context context){
        this.myContext=context;
        myLayoutInflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    static class ViewHolder{
        public ImageView imageView;
        public TextView tv_title;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView=myLayoutInflater.inflate(R.layout.layout_grid_item,null);
            holder= new ViewHolder();
            holder.imageView = (ImageView) convertView.findViewById(R.id.iv_grid);
            holder.tv_title=(TextView) convertView.findViewById(R.id.tv_title);
            convertView.setTag(holder);
        }else {
            holder=(ViewHolder) convertView.getTag();
        }
        //给控件赋值
        holder.tv_title.setText("FGO！");
//        holder.imageView.setImageDrawable();
        return convertView;
    }
}
